/************
	打包签名模块
	Add By : e4ting e4ting@qq.com 2024-05-08 10:01:10
************/
package main

import (
	"os"
	// "fmt"
	"github.com/alecthomas/kingpin/v2"
	utils "cert/pkg"
)

var (
	signMode= kingpin.Flag("sign",    "文件签名").Short('s').Bool()
	pubFile = kingpin.Flag("pub",     "公钥").Short('c').Default("public.pem").Envar("CERT").String()
	keyFile = kingpin.Flag("key",     "私钥").Short('k').Default("key.pem").Envar("KEY").String()
	input   = kingpin.Flag("input",   "文件").Short('i').String()
	output  = kingpin.Flag("output",  "输出").Short('o').Default("").String()
)

func init() {

	kingpin.Version("1.0.1").VersionFlag.Short('v')
	kingpin.Parse()
}

func main(){
	updater := utils.UpgradeCtx{}
	updater.Init(*input, *output, *pubFile, *keyFile)
	if *signMode {
		updater.Sign(*input)
		return
	} else {
		code := updater.Verify()
		if code != nil {
			os.Exit(-1)
		}
		return
	}
}
